/* 
 * Quechua - the lightweight data mining framework
 *
 * Copyright (C) 2012 Marek Denis <quechua@octogan.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef HASHTREE_H
#define HASHTREE_H

#include <vector>
#include <set>
#include "../../../include/types.h"
/**
 * Necesarry methods: add,find,delete
 **/ 

class itemset;
class itemsets;
#include "itemsets.h"

using std::vector;
using std::set;
using std::deque;

struct stdcmp {
   bool operator()(const itemset* a, const itemset* b) const;
};

typedef vector<itemset*> vec;
typedef set<itemset*,stdcmp> set_t;
typedef set_t::iterator set_it;

static const int modulo = 256; //should be 128 or something

enum TREETYPE {
    interior =0,
    leaf
};

class hashnode {
    public:
        TREETYPE type;
        deque<itemset*> items;
        hashnode* children[modulo];

        hashnode();
        hashnode(int d, TREETYPE t);
        virtual ~hashnode();
        bool add(itemset* item,int idx);
        set_t find(const index_t* txn,int size,int idx,int border) const;
        int getdepth() const;
        void setdepth(int x);

        hashnode* getchild(int x) const;

        void clear();
    private:
        int depth;
        static void delitem(itemset* i);
        index_t hash(const index_t& x) const;
        index_t branch(const index_t& x);
};

#endif // HASHTREE_H
